/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Wangyunlai on 2022/07/05.
//

#pragma once

#include "storage/common/table.h"
#include "storage/common/field_meta.h"

// 字段的头文件
class Field
{
public:
  Field() = default;
  Field(const Table *table, const FieldMeta *field) : table_(table), field_(field)
  {}

  // 调用这两个函数能获取到这个类当前的两个private成员
  const Table *table() const { return table_; }
  const FieldMeta *meta() const { return field_; }

  // 属性值，调用这个函数能够敲定字段的数据类型
  // int/long/char/float等
  AttrType attr_type() const
  {
    return field_->type();
  }

  // 这两个函数分别返回的是tablename表名
  // 返回字段的name
  const char *table_name() const { return table_->name(); }
  const char *field_name() const { return field_->name(); }

  // this就是当前对象，调用这个函数就能把这个类的两个private成员成功置值
  void set_table(const Table *table)
  {
    this->table_ = table;
  }
  void set_field(const FieldMeta *field)
  {
    this->field_ = field;
  }
private:
  const Table *table_ = nullptr;
  const FieldMeta *field_ = nullptr;
};
